!function(a) {
    a.fn.layout = function() {
        return a.quiui.run.call(this, "quiLayout", arguments);
    }, a.fn.quiGetLayoutManager = function() {
        return a.quiui.run.call(this, "quiGetLayoutManager", arguments);
    }, a.quiDefaults.Layout = {
        topHeight: 50,
        bottomHeight: 50,
        leftWidth: 110,
        centerWidth: "100%",
        rightWidth: 170,
        InWindow: !0,
        heightDiff: 0,
        height: "100%",
        onHeightChanged: null,
        isLeftCollapse: !1,
        isRightCollapse: !1,
        allowLeftCollapse: !0,
        allowRightCollapse: !0,
        allowLeftResize: !0,
        allowRightResize: !0,
        allowTopResize: !0,
        allowBottomResize: !0,
        space: 3,
        onEndResize: null,
        minLeftWidth: 0,
        minRightWidth: 0
    }, a.quiMethos.Layout = {}, a.quiui.controls.Layout = function(b, c) {
        a.quiui.controls.Layout.base.constructor.call(this, b, c);
    }, a.quiui.controls.Layout.quiExtend(a.quiui.core.UIComponent, {
        __getType: function() {
            return "Layout";
        },
        __idPrev: function() {
            return "Layout";
        },
        _extendMethods: function() {
            return a.quiMethos.Layout;
        },
        _render: function() {
            var d, e, f, g, h, b = this, c = this.options;
            b.layout = a(this.element), b.layout.addClass("l-layout"), b.width = b.layout.width(), 
            a("> div[position=top]", b.layout).length > 0 && (b.top = a("> div[position=top]", b.layout).wrap('<div class="l-layout-top" style="top:0px;"></div>').parent(), 
            b.top.content = a("> div[position=top]", b.top), b.top.content.hasClass("l-layout-content") || b.top.content.addClass("l-layout-content"), 
            b.topHeight = c.topHeight, b.topHeight && (b.top.height(b.topHeight), b.top.content.height(b.topHeight)), 
            d = b.top.content.attr("panelTitle"), d && (b.top.header = a('<div class="l-layout-header"></div>'), 
            b.top.prepend(b.top.header), b.top.header.html(d))), a("> div[position=bottom]", b.layout).length > 0 && (b.bottom = a("> div[position=bottom]", b.layout).wrap('<div class="l-layout-bottom"></div>').parent(), 
            b.bottom.content = a("> div[position=bottom]", b.bottom), b.bottom.content.hasClass("l-layout-content") || b.bottom.content.addClass("l-layout-content"), 
            b.bottomHeight = c.bottomHeight, b.bottomHeight && (b.bottom.height(b.bottomHeight), 
            b.bottom.content.height(b.bottomHeight)), e = b.bottom.content.attr("panelTitle"), 
            e && (b.bottom.header = a('<div class="l-layout-header"></div>'), b.bottom.prepend(b.bottom.header), 
            b.bottom.header.html(e))), a("> div[position=left]", b.layout).length > 0 && (b.left = a("> div[position=left]", b.layout).wrap('<div class="l-layout-left" style="left:0px;"></div>').parent(), 
            b.left.header = a('<div class="l-layout-header"><div class="l-layout-header-toggle"></div><div class="l-layout-header-inner"></div></div>'), 
            b.left.prepend(b.left.header), b.left.header.toggle = a(".l-layout-header-toggle", b.left.header), 
            b.left.content = a("> div[position=left]", b.left), b.left.content.hasClass("l-layout-content") || b.left.content.addClass("l-layout-content"), 
            c.allowLeftCollapse || a(".l-layout-header-toggle", b.left.header).remove(), f = b.left.content.attr("panelTitle"), 
            f && a(".l-layout-header-inner", b.left.header).html(f), b.leftWidth = c.leftWidth, 
            b.leftWidth && b.left.width(b.leftWidth)), a("> div[position=center]", b.layout).length > 0 && (b.center = a("> div[position=center]", b.layout).wrap('<div class="l-layout-center" ></div>').parent(), 
            b.center.content = a("> div[position=center]", b.center), b.center.content.addClass("l-layout-content"), 
            g = b.center.content.attr("panelTitle"), g && (b.center.header = a('<div class="l-layout-header"></div>'), 
            b.center.prepend(b.center.header), b.center.header.html(g)), b.centerWidth = c.centerWidth, 
            b.centerWidth && b.center.width(b.centerWidth)), a("> div[position=right]", b.layout).length > 0 && (b.right = a("> div[position=right]", b.layout).wrap('<div class="l-layout-right"></div>').parent(), 
            b.right.header = a('<div class="l-layout-header"><div class="l-layout-header-toggle"></div><div class="l-layout-header-inner"></div></div>'), 
            b.right.prepend(b.right.header), b.right.header.toggle = a(".l-layout-header-toggle", b.right.header), 
            c.allowRightCollapse || a(".l-layout-header-toggle", b.right.header).remove(), b.right.content = a("> div[position=right]", b.right), 
            b.right.content.hasClass("l-layout-content") || b.right.content.addClass("l-layout-content"), 
            h = b.right.content.attr("panelTitle"), h && a(".l-layout-header-inner", b.right.header).html(h), 
            b.rightWidth = c.rightWidth, b.rightWidth && b.right.width(b.rightWidth)), b.layout.lock = a("<div class='l-layout-lock'></div>"), 
            b.layout.append(b.layout.lock), b._addDropHandle(), b.isLeftCollapse = c.isLeftCollapse, 
            b.isRightCollapse = c.isRightCollapse, b.leftCollapse = a('<div class="l-layout-collapse-left" style="display: none; "><div class="l-layout-collapse-left-toggle"></div></div>'), 
            b.rightCollapse = a('<div class="l-layout-collapse-right" style="display: none; "><div class="l-layout-collapse-right-toggle"></div></div>'), 
            b.layout.append(b.leftCollapse).append(b.rightCollapse), b.leftCollapse.toggle = a("> .l-layout-collapse-left-toggle", b.leftCollapse), 
            b.rightCollapse.toggle = a("> .l-layout-collapse-right-toggle", b.rightCollapse), 
            b._setCollapse(), b._bulid(), a(window).resize(function() {
                b._onResize();
            }), b.set(c), b.mask.height(b.layout.height());
        },
        setLeftCollapse: function(a) {
            var b = this;
            return this.options, b.left ? (b.isLeftCollapse = a, b.isLeftCollapse ? (b.leftCollapse.show(), 
            b.leftDropHandle && b.leftDropHandle.hide(), b.left.hide()) : (b.leftCollapse.hide(), 
            b.leftDropHandle && b.leftDropHandle.show(), b.left.show()), b._onResize(), setTimeout(function() {
                b._onResize();
            }, 200), b.trigger("endResize"), void 0) : !1;
        },
        setRightCollapse: function(a) {
            var b = this;
            return this.options, b.right ? (b.isRightCollapse = a, b._onResize(), b.isRightCollapse ? (b.rightCollapse.show(), 
            b.rightDropHandle && b.rightDropHandle.hide(), b.right.hide()) : (b.rightCollapse.hide(), 
            b.rightDropHandle && b.rightDropHandle.show(), b.right.show()), setTimeout(function() {
                b._onResize();
            }, 200), b.trigger("endResize"), void 0) : !1;
        },
        _bulid: function() {
            var b = this, c = this.options;
            a("> .l-layout-left .l-layout-header,> .l-layout-right .l-layout-header", b.layout).hover(function() {
                a(this).addClass("l-layout-header-over");
            }, function() {
                a(this).removeClass("l-layout-header-over");
            }), a(".l-layout-header-toggle", b.layout).hover(function() {
                a(this).addClass("l-layout-header-toggle-over");
            }, function() {
                a(this).removeClass("l-layout-header-toggle-over");
            }), a(".l-layout-header-toggle", b.left).click(function() {
                b.setLeftCollapse(!0);
            }), a(".l-layout-header-toggle", b.right).click(function() {
                b.setRightCollapse(!0);
            }), b.middleTop = 0, b.top && (b.middleTop += b.top.height(), b.middleTop += parseInt(b.top.css("borderTopWidth")), 
            b.middleTop += parseInt(b.top.css("borderBottomWidth")), b.middleTop += c.space), 
            b.left && (b.left.css({
                top: b.middleTop
            }), b.leftCollapse.css({
                top: b.middleTop
            })), b.center && b.center.css({
                top: b.middleTop
            }), b.right && (b.right.css({
                top: b.middleTop
            }), b.rightCollapse.css({
                top: b.middleTop
            })), b.left && b.left.css({
                left: 0
            }), b._onResize(), b._onResize();
        },
        _setCollapse: function() {
            var b = this;
            this.options, b.leftCollapse.hover(function() {
                a(this).addClass("l-layout-collapse-left-over");
            }, function() {
                a(this).removeClass("l-layout-collapse-left-over");
            }), b.leftCollapse.toggle.hover(function() {
                a(this).addClass("l-layout-collapse-left-toggle-over");
            }, function() {
                a(this).removeClass("l-layout-collapse-left-toggle-over");
            }), b.rightCollapse.hover(function() {
                a(this).addClass("l-layout-collapse-right-over");
            }, function() {
                a(this).removeClass("l-layout-collapse-right-over");
            }), b.rightCollapse.toggle.hover(function() {
                a(this).addClass("l-layout-collapse-right-toggle-over");
            }, function() {
                a(this).removeClass("l-layout-collapse-right-toggle-over");
            }), b.leftCollapse.toggle.click(function() {
                b.setLeftCollapse(!1);
            }), b.rightCollapse.toggle.click(function() {
                b.setRightCollapse(!1);
            }), b.left && b.isLeftCollapse && (b.leftCollapse.show(), b.leftDropHandle && b.leftDropHandle.hide(), 
            b.left.hide()), b.right && b.isRightCollapse && (b.rightCollapse.show(), b.rightDropHandle && b.rightDropHandle.hide(), 
            b.right.hide());
        },
        _addDropHandle: function() {
            var b = this, c = this.options;
            b.left && c.allowLeftResize && (b.leftDropHandle = a("<div class='l-layout-drophandle-left'></div>"), 
            b.layout.append(b.leftDropHandle), b.leftDropHandle && b.leftDropHandle.show(), 
            b.leftDropHandle.mousedown(function(a) {
                b._start("leftresize", a);
            })), b.right && c.allowRightResize && (b.rightDropHandle = a("<div class='l-layout-drophandle-right'></div>"), 
            b.layout.append(b.rightDropHandle), b.rightDropHandle && b.rightDropHandle.show(), 
            b.rightDropHandle.mousedown(function(a) {
                b._start("rightresize", a);
            })), b.top && c.allowTopResize && (b.topDropHandle = a("<div class='l-layout-drophandle-top'></div>"), 
            b.layout.append(b.topDropHandle), b.topDropHandle.mousedown(function(a) {
                b._start("topresize", a);
            })), b.bottom && c.allowBottomResize && (b.bottomDropHandle = a("<div class='l-layout-drophandle-bottom'></div>"), 
            b.layout.append(b.bottomDropHandle), b.bottomDropHandle.mousedown(function(a) {
                b._start("bottomresize", a);
            })), b.draggingxline = a("<div class='l-layout-dragging-xline'></div>"), b.draggingyline = a("<div class='l-layout-dragging-yline'></div>"), 
            b.mask = a("<div class='l-dragging-mask'></div>"), b.layout.append(b.draggingxline).append(b.draggingyline).append(b.mask);
        },
        _setDropHandlePosition: function() {
            var a = this, b = this.options;
            a.leftDropHandle && a.leftDropHandle.css({
                left: a.left.width() + parseInt(a.left.css("left")),
                height: a.middleHeight,
                top: a.middleTop
            }), a.rightDropHandle && a.rightDropHandle.css({
                left: parseInt(a.right.css("left")) - b.space,
                height: a.middleHeight,
                top: a.middleTop
            }), a.topDropHandle && a.topDropHandle.css({
                top: a.top.height() + parseInt(a.top.css("top")),
                width: a.top.width()
            }), a.bottomDropHandle && a.bottomDropHandle.css({
                top: parseInt(a.bottom.css("top")) - b.space,
                width: a.bottom.width()
            });
        },
        _onResize: function() {
            var h, i, b = this, c = this.options, d = b.layout.height(), e = 0, f = a(window).height(), g = null;
            "string" == typeof c.height && c.height.indexOf("%") > 0 ? (h = b.layout.parent(), 
            c.InWindow || "body" == h[0].tagName.toLowerCase() ? (g = f, g -= parseInt(a("body").css("paddingTop")), 
            g -= parseInt(a("body").css("paddingBottom"))) : g = h.height(), e = .01 * g * parseFloat(c.height), 
            (c.InWindow || "body" == h[0].tagName.toLowerCase()) && (e -= b.layout.offset().top - parseInt(a("body").css("paddingTop")))) : e = parseInt(c.height), 
            e += c.heightDiff, b.layout.height(e), b.layoutHeight = b.layout.height(), b.middleWidth = b.layout.width(), 
            b.middleHeight = b.layout.height(), b.top && (b.middleHeight -= b.top.height(), 
            b.middleHeight -= parseInt(b.top.css("borderTopWidth")), b.middleHeight -= parseInt(b.top.css("borderBottomWidth")), 
            b.middleHeight -= c.space), b.bottom && (b.middleHeight -= b.bottom.height(), b.middleHeight -= parseInt(b.bottom.css("borderTopWidth")), 
            b.middleHeight -= parseInt(b.bottom.css("borderBottomWidth")), b.middleHeight -= c.space), 
            b.middleHeight -= 2, b.hasBind("heightChanged") && b.layoutHeight != d && b.trigger("heightChanged", [ {
                layoutHeight: b.layoutHeight,
                diff: b.layoutHeight - d,
                middleHeight: b.middleHeight
            } ]), b.center && (b.centerWidth = b.middleWidth, b.left && (b.isLeftCollapse ? (b.centerWidth -= b.leftCollapse.width(), 
            b.centerWidth -= parseInt(b.leftCollapse.css("borderLeftWidth")), b.centerWidth -= parseInt(b.leftCollapse.css("borderRightWidth")), 
            b.centerWidth -= parseInt(b.leftCollapse.css("left")), b.centerWidth -= c.space) : (b.centerWidth -= b.leftWidth, 
            b.centerWidth -= parseInt(b.left.css("borderLeftWidth")), b.centerWidth -= parseInt(b.left.css("borderRightWidth")), 
            b.centerWidth -= parseInt(b.left.css("left")), b.centerWidth -= c.space)), b.right && (b.isRightCollapse ? (b.centerWidth -= b.rightCollapse.width(), 
            b.centerWidth -= parseInt(b.rightCollapse.css("borderLeftWidth")), b.centerWidth -= parseInt(b.rightCollapse.css("borderRightWidth")), 
            b.centerWidth -= parseInt(b.rightCollapse.css("right")), b.centerWidth -= c.space) : (b.centerWidth -= b.rightWidth, 
            b.centerWidth -= parseInt(b.right.css("borderLeftWidth")), b.centerWidth -= parseInt(b.right.css("borderRightWidth")), 
            b.centerWidth -= c.space)), b.centerLeft = 0, b.left && (b.isLeftCollapse ? (b.centerLeft += b.leftCollapse.width(), 
            b.centerLeft += parseInt(b.leftCollapse.css("borderLeftWidth")), b.centerLeft += parseInt(b.leftCollapse.css("borderRightWidth")), 
            b.centerLeft += parseInt(b.leftCollapse.css("left")), b.centerLeft += c.space) : (b.centerLeft += b.left.width(), 
            b.centerLeft += parseInt(b.left.css("borderLeftWidth")), b.centerLeft += parseInt(b.left.css("borderRightWidth")), 
            b.centerLeft += c.space)), b.center.css({
                left: b.centerLeft
            }), b.center.width(b.centerWidth), b.center.height(b.middleHeight), i = b.middleHeight, 
            b.center.header && (i -= b.center.header.height()), b.center.content.height(i)), 
            b.left && (b.leftCollapse.height(b.middleHeight), b.left.height(b.middleHeight)), 
            b.right && (b.rightCollapse.height(b.middleHeight), b.right.height(b.middleHeight), 
            b.rightLeft = 0, b.left && (b.isLeftCollapse ? (b.rightLeft += b.leftCollapse.width(), 
            b.rightLeft += parseInt(b.leftCollapse.css("borderLeftWidth")), b.rightLeft += parseInt(b.leftCollapse.css("borderRightWidth")), 
            b.rightLeft += c.space) : (b.rightLeft += b.left.width(), b.rightLeft += parseInt(b.left.css("borderLeftWidth")), 
            b.rightLeft += parseInt(b.left.css("borderRightWidth")), b.rightLeft += parseInt(b.left.css("left")), 
            b.rightLeft += c.space)), b.center && (b.rightLeft += b.center.width(), b.rightLeft += parseInt(b.center.css("borderLeftWidth")), 
            b.rightLeft += parseInt(b.center.css("borderRightWidth")), b.rightLeft += c.space), 
            b.right.css({
                left: b.rightLeft
            })), b.bottom && (b.bottomTop = b.layoutHeight - b.bottom.height() - 2, b.bottom.css({
                top: b.bottomTop
            })), b._setDropHandlePosition();
        },
        _start: function(b, c) {
            var d = this;
            if (this.options, d.dragtype = b, "leftresize" == b || "rightresize" == b) d.xresize = {
                startX: c.pageX
            }, d.draggingyline.css({
                left: c.pageX - d.layout.offset().left,
                height: d.middleHeight,
                top: d.middleTop
            }).show(), a("body").css("cursor", "col-resize"), d.mask.height(d.layout.height()).removeClass("l-layout-ymask").addClass("l-layout-xmask").show(); else {
                if ("topresize" != b && "bottomresize" != b) return;
                d.yresize = {
                    startY: c.pageY
                }, d.draggingxline.css({
                    top: c.pageY - d.layout.offset().top,
                    width: d.layout.width()
                }).show(), a("body").css("cursor", "row-resize"), d.mask.height(d.layout.height()).removeClass("l-layout-xmask").addClass("l-layout-ymask").show();
            }
            d.layout.lock.width(d.layout.width()), d.layout.lock.height(d.layout.height()), 
            d.layout.lock.show(), (a.browser.msie || a.browser.safari) && a("body").bind("selectstart", function() {
                return !1;
            }), a(document).bind("mouseup", function() {
                d._stop.apply(d, arguments);
            }), a(document).bind("mousemove", function() {
                d._drag.apply(d, arguments);
            });
        },
        _drag: function(b) {
            var c = this;
            this.options, c.xresize ? (c.xresize.diff = b.pageX - c.xresize.startX, c.draggingyline.css({
                left: b.pageX - c.layout.offset().left
            }), a("body").css("cursor", "col-resize")) : c.yresize && (c.yresize.diff = b.pageY - c.yresize.startY, 
            c.draggingxline.css({
                top: b.pageY - c.layout.offset().top
            }), a("body").css("cursor", "row-resize"));
        },
        _stop: function(b) {
            var e, f, c = this, d = this.options;
            if (c.xresize && void 0 != c.xresize.diff) {
                if (e = c.xresize.diff, "leftresize" == c.dragtype) {
                    if (d.minLeftWidth && c.leftWidth + c.xresize.diff < d.minLeftWidth) return;
                    c.leftWidth += c.xresize.diff, c.left.width(c.leftWidth), c.center ? c.center.width(c.center.width() - c.xresize.diff).css({
                        left: parseInt(c.center.css("left")) + c.xresize.diff
                    }) : c.right && c.right.width(c.left.width() - c.xresize.diff).css({
                        left: parseInt(c.right.css("left")) + c.xresize.diff
                    });
                } else if ("rightresize" == c.dragtype) {
                    if (d.minRightWidth && c.rightWidth - c.xresize.diff < d.minRightWidth) return;
                    c.rightWidth -= c.xresize.diff, c.right.width(c.rightWidth).css({
                        left: parseInt(c.right.css("left")) + c.xresize.diff
                    }), c.center ? c.center.width(c.center.width() + c.xresize.diff) : c.left && c.left.width(c.left.width() + c.xresize.diff);
                }
            } else c.yresize && void 0 != c.yresize.diff && (e = c.yresize.diff, "topresize" == c.dragtype ? (c.top.height(c.top.height() + c.yresize.diff), 
            c.middleTop += c.yresize.diff, c.middleHeight -= c.yresize.diff, c.left && (c.left.css({
                top: c.middleTop
            }).height(c.middleHeight), c.leftCollapse.css({
                top: c.middleTop
            }).height(c.middleHeight)), c.center && c.center.css({
                top: c.middleTop
            }).height(c.middleHeight), c.right && (c.right.css({
                top: c.middleTop
            }).height(c.middleHeight), c.rightCollapse.css({
                top: c.middleTop
            }).height(c.middleHeight))) : "bottomresize" == c.dragtype && (c.bottom.height(c.bottom.height() - c.yresize.diff), 
            c.middleHeight += c.yresize.diff, c.bottomTop += c.yresize.diff, c.bottom.css({
                top: c.bottomTop
            }), c.left && (c.left.height(c.middleHeight), c.leftCollapse.height(c.middleHeight)), 
            c.center && c.center.height(c.middleHeight), c.right && (c.right.height(c.middleHeight), 
            c.rightCollapse.height(c.middleHeight))), f = c.middleHeight, c.center.header && (f -= c.center.header.height()), 
            c.center.content.height(f), c.top && c.top.content.height(c.top.height()), c.bottom && c.bottom.content.height(c.bottom.height()));
            c.trigger("endResize", [ {
                direction: c.dragtype ? c.dragtype.replace(/resize/, "") : "",
                diff: e
            }, b ]), c._setDropHandlePosition(), c.draggingxline.hide(), c.draggingyline.hide(), 
            c.mask.hide(), c.xresize = c.yresize = c.dragtype = !1, c.layout.lock.hide(), (a.browser.msie || a.browser.safari) && a("body").unbind("selectstart"), 
            a(document).unbind("mousemove", c._drag), a(document).unbind("mouseup", c._stop), 
            a("body").css("cursor", "");
        }
    });
}(jQuery);